package com.liushuai.phoneguardian.ui;

import com.liushuai.phoneguardian.R;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class SettingView extends RelativeLayout {

	private View view;
	private TextView tv_setting_view_title;
	private TextView tv_setting_view_content;
	private CheckBox checkBox;
	private String checkedtext;
	private String uncheckedtext;

	public SettingView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
		init(context);
	}

	public SettingView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		init(context);

	}

	public SettingView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		init(context);
		TypedArray a = context.obtainStyledAttributes(attrs,
				R.styleable.ui_setting_view);
		String content = a.getString(R.styleable.ui_setting_view_content);
		String title = a.getString(R.styleable.ui_setting_view_title);
		tv_setting_view_title.setText(title);
		tv_setting_view_content.setText(content);
		checkedtext = a.getString(R.styleable.ui_setting_view_checkedtext);
		uncheckedtext = a.getString(R.styleable.ui_setting_view_uncheckedtext);
		a.recycle();
	}

	private void init(Context context) {
		view = View.inflate(context, R.layout.ui_setting_view, this);
		tv_setting_view_title = (TextView) view
				.findViewById(R.id.tv_setting_view_title);
		tv_setting_view_content = (TextView) view
				.findViewById(R.id.tv_setting_view_content);
		checkBox = (CheckBox) findViewById(R.id.cb_setting_view);

	}

	public boolean isChecked() {
		return checkBox.isChecked();
	}

	public void setChecked(boolean b) {
		checkBox.setChecked(b);
		if (isChecked()) {
			setContentText(checkedtext);
		} else {
			setContentText(uncheckedtext);
		}
	}

	public void setContentText(String text) {
		tv_setting_view_content.setText(text);
	}

}
